package IO流.缓冲流.练习;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class 视频csb {
    public static void main(String[] args) throws IOException {
        //1.创建出师表的缓冲流对象
        BufferedReader br=new BufferedReader(new FileReader("F\\csb.txt"));
        BufferedWriter bw=new BufferedWriter(new FileWriter("F\\copy.txt"));

        //2.读取数据
        ArrayList<String> list=new ArrayList<>();
        String line;
        while ((line= br.readLine())!=null){
            list.add(line);
        }
        //3.排序
        //排序规则:根据每行的第一个序号进行排序
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                //o1:是红黑树中已经存在的值
                //o2:是要进行添加的值
                //获取o1,o2的序号
                int i1 = Integer.parseInt(o1.split("\\.")[0]);
                int i2 = Integer.parseInt(o2.split("\\.")[0]);
                return i1-i2;
            }
        });
        //4.写出
        for (String s : list) {
            bw.write(s);
            bw.newLine();
        }
        //4.释放资源
        bw.close();
        br.close();

    }
}
